import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_ability/custom_ui.dart';
/// TabBar
class YJTabBar extends StatefulWidget {
  YJTabBar({
    Key? key,
    required this.tabs,
    required this.onFunction,
    this.tabBarHeight,
    this.width,
    this.isIndicator = false,
    this.tabBarColor,
    this.labelSize,
    this.unselectedLabelSize,
    this.labelColor,
    this.unselectedLabelColor,
    this.shape,
  }) : super(key: key);

  /// 高
  final double? tabBarHeight;

  /// 宽
  final double? width;

  /// bar颜色
  final Color? tabBarColor;

  /// 指示器 是否显示
  final bool? isIndicator;

  /// 点击切换时回调index
  Function(int index) onFunction;

  /// 显示的标签内容
  final List<BarItem> tabs;

  /// 边框
  final ShapeBorder? shape;

  /// 字体大小
  final double? labelSize;

  /// 未选中字体大小
  final double? unselectedLabelSize;

  /// 选中label颜色
  final Color? labelColor;

  /// 未选中label颜色
  final Color? unselectedLabelColor;

  @override
  _YJTabBarState createState() => _YJTabBarState();
}

class _YJTabBarState extends State<YJTabBar> {
  ScrollController? _scrollController;
  DragStartBehavior dragStartBehavior = DragStartBehavior.start;

  @override
  Widget build(BuildContext context) => SingleChildScrollView(
        dragStartBehavior: dragStartBehavior,
        scrollDirection: Axis.horizontal,
        controller: _scrollController,
        child: Container(
          width: widget.width ?? MediaQuery.of(context).size.width,
          height:
              widget.tabBarHeight ?? MediaQuery.of(context).size.height * 0.1,
          child: Material(
            shape: widget.shape,
            type: MaterialType.button,
            color: widget.tabBarColor ?? YJColors.TRANSPARENT,
            child: YJTabs(
              onFunction: widget.onFunction,
              tabs: widget.tabs,
              isIndicator: widget.isIndicator,
              labelSize: widget.labelSize,
              unselectedLabelSize: widget.unselectedLabelSize,
              labelColor: widget.labelColor,
              unselectedLabelColor: widget.unselectedLabelColor,
            ),
          ),
        ),
      );
}
